#include "ScnsIwdg.c.h"

#if defined(SCNS_IWDG_ENABLE)&&SCNS_IWDG_ENABLE==1
#include "HAL_device.h"
#include "HAL_conf.h"

ScnsStatus scnsBspIwdgInit(void)
{
    /*Start the internal low-speed clock and wait for the clock to be ready*/
    RCC_LSICmd(ENABLE);
    while(RCC_GetFlagStatus(RCC_FLAG_LSIRDY) == RESET);

    /*Set clock prescaler*/
    PVU_CheckStatus();
    IWDG_WriteAccessCmd(0x5555);
    IWDG_SetPrescaler(IWDG_Prescaler_256);
    PVU_CheckStatus();
    /*Set the overload register value*/
    RVU_CheckStatus();
    IWDG_WriteAccessCmd(0x5555);
    IWDG_SetReload(0xfff);
    RVU_CheckStatus();
    /*Load and enable counters*/
    IWDG_ReloadCounter();
    IWDG_Enable();
    //((DBG_Type*)(0x40007084))->CR|=DBG_CR_DEBUGIWDGSTOP(1);
    return SCNS_STATUS_OK;
}
ScnsStatus scnsBspIwdgPostInit(void)
{
    return SCNS_STATUS_OK;
}
void scnsBspIwdgFeed(void)
{
    IWDG_ReloadCounter();
}

#endif